import React,{ useEffect } from "react";
import {Modal,Form,Input } from "antd";
import { update } from "../../services/classify";
import {useSelector,useDispatch} from 'react-redux';
import { setUpdateVisible } from "../../store/slice/classifySlice";

 

export default function Update({show}) {
    const [form] = Form.useForm();
    let {updateVisible,classify} = useSelector(state => state.classify);
   let dispatch=useDispatch();
    const handleOk = async () => {
        await update({_id:classify._id,...form.getFieldsValue()});
        show();
        dispatch(setUpdateVisible(false))

    };

    const handleCancel = () => {
        dispatch(setUpdateVisible(false))
    };
    useEffect(()=>{
        form.setFieldsValue(classify);
        
    },[classify._id])

    return (
        <div>
           
            <Modal
                title="修改类型"
                visible={updateVisible}
                onOk={handleOk}
                onCancel={handleCancel}
            >
                <Form
                    name="addForm"
                    form={form}
                    labelCol={{
                        span: 4,
                    }}
                    wrapperCol={{
                        span: 20,
                    }}
                    autoComplete="off"
                >
                  
                    <Form.Item
                        label="类型"
                        name="sort"
                        hasFeedback
                        rules={[
                            {
                                required: true,
                                message: "类型不能为空",
                            },
                        ]}
                    >
                        <Input />
                    </Form.Item>

                   
                
                </Form>
            </Modal>
        </div>
    );
}